% procedure calcE_t_LV 
% function that calculates time-varying elastance for LV 

HandleEditTextHR=findobj(gcf,'Tag','EditTextHR');
HR=str2num(get(HandleEditTextHR,'String'));

HandleEditTextT_interval=findobj(gcf,'Tag','EditTextT_interval');
t_interval=str2num(get(HandleEditTextT_interval,'String'));

T=60/HR;
time=(t_interval:t_interval:T)';			% make a column vector representing time
npoints=length(time);

if loadelastV==1			% default Double Hill curve 
	fid1=fopen('defaultDH_LV.txt','r');   
   if fid1==-1
		amp_HillV=1.2;
		t01_HillV=0.2;
		t02_HillV=0.44;
		n_HillV=2.4;
      m_HillV=17;
   else   
      amp_HillV=fscanf(fid1,'amp_Hill\t%g\n',1);
      t01_HillV=fscanf(fid1,'t01_Hill\t%g\n',1);
		t02_HillV=fscanf(fid1,'t02_Hill\t%g\n',1);
		n_HillV=fscanf(fid1,'n_Hill\t%g\n',1);
      m_HillV=fscanf(fid1,'m_Hill\t%g\n',1);
      fclose(fid1);
   end   
	tN=time/T;
	E_t_LV=Hill_elastance(tN,amp_HillV,t01_HillV,t02_HillV,n_HillV,m_HillV);

elseif loadelastV==2		% normalized curve (Senzaki et al.)
   tN=time/TEmaxV;
   E_t_LV=norm_Kass(tN);
   E_t_LV=E_t_LV+(E_t_LV(1)-E_t_LV(npoints))*(time-T)/T;		% detrend E(t) so that beginning and end are same point
   E_t_LV=E_t_LV-min(E_t_LV);
   
elseif loadelastV==3		% customized Double Hill curve
   Fig_DoubleHill;		% opens Fig_DoubleHill
   draw_Hill;
   uiwait;
   E_t_LV=E_t_DoubleHill;

elseif loadelastV==4		% normalized RV curve dogs(data P Wouters)
   tN=time/TEmaxV;
   E_t_LV=norm_RVdog(tN);
   E_t_LV=E_t_LV+(E_t_LV(1)-E_t_LV(npoints))*(time-T)/T;		% detrend E(t) so that beginning and end are same point
   E_t_LV=E_t_LV-min(E_t_LV);
   
end;     
   
% re-normalize ventricular elastance curve

E_t_LV=E_t_LV/max(E_t_LV);	
E_t_LV=EminV+E_t_LV*(EmaxV-EminV);



